package logic

import (
	"context"
	"zhihu/zhihurpc/models/mysql"

	"zhihu/zhihurpc/internal/svc"
	"zhihu/zhihurpc/zhihurpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProblemshowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewProblemshowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProblemshowLogic {
	return &ProblemshowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ProblemshowLogic) Problemshow(in *zhihurpc.ProblemshowRequest) (*zhihurpc.ProblemshowResponse, error) {
	// todo: add your logic here and delete this line
	var problem mysql.Problem
	mysql.DB.Debug().Where("id=?", in.ProblemId).Find(&problem)
	problem.Hot = problem.Hot + 1
	mysql.DB.Debug().Updates(&problem)
	return &zhihurpc.ProblemshowResponse{
		Id:      int64(problem.ID),
		Content: problem.Content,
		UserId:  problem.UserId,
	}, nil
}
